package book.nettyinaction.ch05;

import java.nio.ByteBuffer;

/**
 *
 * 代码清单 5-3  使用 ByteBuffer 的复合缓冲区模式
 *
 */
public class Demo003ByteBuffer {

    public static void main(String[] args) {
        ByteBuffer header = ByteBuffer.allocate(10);
        ByteBuffer body = ByteBuffer.allocateDirect(50);


        // Use an array to hold the message parts
        ByteBuffer[] message = new ByteBuffer[] { header, body };
        // Create a new ByteBuffer and use copy to merge the header and body
        ByteBuffer message2 = ByteBuffer.allocate(header.remaining() + body.remaining());

        message2.put( header );
        message2.put( body );
        message2.flip();
    }
}
